Goal: decide number of pops, maternal families, etc. Then planting design. Parameters: maximize number of pops, then number of maternal families. Plant 2000.
library(tidyverse)
Registered S3 methods overwritten by 'dbplyr':
method from
print.tbl_lazy
print.tbl_sql
── Attaching packages ───────────────────────────────────────── tidyverse 1.3.1 ──
✓ ggplot2 3.3.5 ✓ purrr 0.3.4
✓ tibble 3.1.6 ✓ dplyr 1.0.8
✓ tidyr 1.2.0 ✓ stringr 1.4.0
✓ readr 2.1.2 ✓ forcats 0.5.1
── Conflicts ──────────────────────────────────────────── tidyverse_conflicts() ──
x dplyr::filter() masks stats::filter()
x dplyr::lag() masks stats::lag()
library(googlesheets4)
library(ggforce)
is.even <- function(x) x%%2 == 0
pops <- read_sheet("https://docs.google.com/spreadsheets/d/1dif9Y5hbkSa56Bgonj04-jXh8jNc6f13RBS6BPUf1IQ",
skip=1,
na=c("NA", ""),
col_types = c("ciiicccc"),
.name_repair = "universal") %>%
mutate(approx.number.seeds = as.integer(str_remove_all(approx.number.seeds,"[^0-9]")))
Is it OK to cache OAuth access credentials in the folder ~/Library/Caches/gargle
between R sessions?
1: Yes
2: No
1
Waiting for authentication in browser...
Press Esc/Ctrl + C to abort
Authentication complete.
✓ Reading from Int Bio parents seed stock.
✓ Range 2:5000000.
New names:
• `parent pop` -> `parent.pop`
• `collection year` -> `collection.year`
• `maternal families` -> `maternal.families`
• `approx number seeds` -> `approx.number.seeds`
• `collection priority?` -> `collection.priority.`
• `on climate PCA?` -> `on.climate.PCA.`
pops
pops.filtered <- pops %>% group_by(parent.pop) %>% slice_max(order_by=maternal.families) %>%
filter(approx.number.seeds >= 100) %>%
filter(!(parent.pop %in% c("HH", "RB"))) # old seed
pops.filtered %>% arrange(maternal.families)
sum(pops.filtered$maternal.families>=8)
[1] 21
sum(pops.filtered$maternal.families>=15)
[1] 18
Plant 21 pops * 8 families * 12 reps (= 2016 plants)
Plant 11 pops * 15 families * 12 reps (= 1980 plants)
3 mfs from WV, 4 mfs WR and 7 mfs from everyone else
total mfs = 3+4+721 = 168 13 reps (= 2002 plants)
2000 plants. think of 10 blocks of 200
200 = 4*50
Create grid
plants <- 2000
blocks <- 10
columns <- 4
rows <- plants/blocks/columns
size <- 20 # plant diameter
radius <- size/2
aisle <- 90
plan1 <- expand_grid(block=LETTERS[1:blocks],
column=1:columns,
row=1:rows,
radius=radius)
plan1
add positions
column_offset <- sqrt((2*radius)^2 - radius^2) # Pythagorean theorem for offset spacing
plan1 <- plan1 %>%
mutate(y_pos=ifelse(is.even(column),
row*size,
row*size-radius),
x_pos=ifelse(column==1,
radius,
radius+(column-1)*column_offset))
plan1
plan1 %>% #filter(block=="A", row <6) %>%
ggplot(aes(x0=x_pos, y0=y_pos, r=radius)) +
geom_circle(fill="lightgreen", alpha=.25) +
coord_equal() +
facet_wrap(~block, ncol = 10)
update to position blocks
# only offset x_positions (1 "row" of blocks)
plan1 <- plan1 %>%
mutate(block_x_offset = as.integer(as.factor(block))-1,
block_x_offset = block_x_offset* (aisle + size + (columns-1)*column_offset))
plan1 %>% #filter(block=="A", row <6) %>%
ggplot(aes(x0=x_pos+block_x_offset, y0=y_pos, r=radius)) +
geom_circle(fill="lightgreen", alpha=.25) +
coord_equal()